using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pow {
	public class GameplayState : DrawableGameComponent {
		HUD hud;
		Game1 game;
		Jogador jogador;
		Enemy inimigo;
        Gameover gameover;

		EnemyFactory enemyFactory;

		public GameplayState(Game game)
			: base(game) {
			this.game = game as Game1;
		}

		public override void Initialize() {
			base.Initialize();
			hud = new HUD(game);
			jogador = new Jogador(game);
			inimigo = new Enemy(game, jogador);
            gameover = new Gameover(game);
			enemyFactory = new EnemyFactory(game, jogador);
			enemyFactory.totalEnemies = 15;

			//enemyPool=new List<Enemy>();
			//for(int i=0;i<totalEnemies;i++)
			//    enemyPool.Add(enemyFactory.createEnemy());
		}

		public override void Update(GameTime gameTime) {

            hud.update(gameTime, jogador);

			//enemyFactory.createEnemy();
			//enemyPool.Add(enemyFactory.createEnemy());

			//foreach (Enemy e in enemyPool)
			//{
			//    e.Update(gameTime);
			//    jogador.Update(gameTime, e);
			//}
			enemyFactory.Update(gameTime);
			jogador.Update(gameTime, enemyFactory);

			base.Update(gameTime);
		}

		public override void Draw(GameTime gameTime) {
			game.spriteBatch.Begin();

			jogador.draw(gameTime);
			enemyFactory.Draw(gameTime);
            hud.drawLifeBar(gameTime);
            if (jogador.gameover)
            {
                gameover.draw(gameTime, jogador);
            }


			//foreach(Enemy e in enemyPool)
			//    e.Draw(gameTime);

			game.spriteBatch.End();
		}

	}
}
